#!/usr/bin/python

import sys;
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
import numpy as np

samples = []

for line in sys.stdin:
    fields = line.split( ' ' )
    delay, throughput = float(fields[ 0 ]), float(fields[ 1 ])
    samples.append( [ delay, throughput ] )

samples = np.matrix( samples )

# taken from https://github.com/joferkington/oost_paper_code/blob/master/error_ellipse.py

def get_ellipse(points, nstd=1):
    def eigsorted(cov):
        vals, vecs = np.linalg.eigh(cov)
        order = vals.argsort()[::-1]
        return vals[order], vecs[:,order]

    cov = np.cov(points, rowvar=False)
    vals, vecs = eigsorted(cov)
    theta = np.degrees(np.arctan2(*vecs[:,0][::-1]))

    # Width and height are "full" widths, not radius
#    width, height = 2 * nstd * np.sqrt(vals)
    width, height = nstd * np.sqrt(vals)
    return [ width, height, theta ]

def get_ellipse_coords(a=0.0, b=0.0, x=0.0, y=0.0, angle=0.0, k=2):
    """ Draws an ellipse using (360*k + 1) discrete points; based on pseudo code
    given at http://en.wikipedia.org/wiki/Ellipse
    k = 1 means 361 points (degree by degree)
    a = major axis distance,
    b = minor axis distance,
    x = offset along the x-axis
    y = offset along the y-axis
    angle = clockwise rotation [in degrees] of the ellipse;
        * angle=0  : the ellipse is aligned with the positive x-axis
        * angle=30 : rotated 30 degrees clockwise from positive x-axis
    """
    pts = np.zeros((360*k+1, 2))

    beta = -angle * np.pi/180.0
    sin_beta = np.sin(beta)
    cos_beta = np.cos(beta)
    alpha = np.radians(np.r_[0.:360.:1j*(360*k+1)])
 
    sin_alpha = np.sin(alpha)
    cos_alpha = np.cos(alpha)
    
    pts[:, 0] = x + (a * cos_alpha * cos_beta - b * sin_alpha * sin_beta)
    pts[:, 1] = y + (a * cos_alpha * sin_beta + b * sin_alpha * cos_beta)

    return pts

means = np.mean( samples, axis=0 )

center_x = means[ 0, 0 ]
center_y = means[ 0, 1 ]
width, height, theta = get_ellipse( samples )

#print center_x, center_y
#print width, height, theta

for i in get_ellipse_coords(width, height, center_x, center_y, -theta ):
    print i[ 0 ], i[ 1 ]
